package com.helloandroid.activesitting.util;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.helloandroid.activesitting.ApplicationObject;
import com.helloandroid.activesitting.bo.WorkTime;

public class PreferencesManager {
	private static volatile PreferencesManager instance = null;
	SharedPreferences settings;

	private PreferencesManager() {
		settings = PreferenceManager.getDefaultSharedPreferences(ApplicationObject.ApplicationContext);
	}

	public static PreferencesManager getInstance() {
		if (instance == null) {
			instance = new PreferencesManager();
		}

		return instance;
	}
	
	public WorkTime getWorkStartTime(){
		String startTime = instance.settings.getString("work_start_time", "08:00");
		String[] timeParts = startTime.split(":");
		int hour = Integer.parseInt(timeParts[0]);
		int minute = Integer.parseInt(timeParts[1]);
		
		return new WorkTime(hour, minute);
	}
	
	public WorkTime getWorkEndTime(){
		String startTime = instance.settings.getString("work_end_time", "17:00");
		String[] timeParts = startTime.split(":");
		int hour = Integer.parseInt(timeParts[0]);
		int minute = Integer.parseInt(timeParts[1]);
		
		return new WorkTime(hour, minute);
	}
	
	public boolean isLaunchTime(){
		return instance.settings.getBoolean("KEY_LUNCH_ENABLED", false);
	}
	
	public WorkTime getLaunchStartTime(){
		String startTime = instance.settings.getString("lunch_start_time", "12:00");
		String[] timeParts = startTime.split(":");
		int hour = Integer.parseInt(timeParts[0]);
		int minute = Integer.parseInt(timeParts[1]);
		
		return new WorkTime(hour, minute);
	}
	
	

}
